#!/usr/env/bin python
# -*- coding: utf-8 -*-

# @Time    : 2018/11/13 18:14
# @Author  : yangdy
# @Email   : yangdy@egu360.com
# @File    : 中级-逆波兰表达式求值.py
# @Software: PyCharm

class Solution:
    def evalRPN(self, tokens):
        """
        :type tokens: List[str]
        :rtype: int
        """
        data = []
        for p in tokens:
            if p in '+-*/':
                y = data.pop()
                x = data.pop()
                if p == '+':
                    data.append(x + y)
                elif p == '-':
                    data.append(x - y)
                elif p == '*':
                    data.append(x * y)
                elif p == '/':
                    if x * y < 0 and x % y != 0:
                        data.append(x // y + 1)
                    else:
                        data.append(x // y)
                # print(x, y)
            else:
                data.append(int(p))
            # print(p)
            # print(data)
        return data.pop()


def opt(tokens):
    solve = Solution()
    print('tokens:', tokens)
    print(solve.evalRPN(tokens))


def main():
    problems = [
        ["4", "13", "5", "/", "+"],
        ["2", "1", "+", "3", "*"],
        ["10", "6", "9", "3", "+", "-11", "*", "/", "*", "17", "+", "5", "+"],
    ]

    for p in problems:
        opt(p)

    print(6, -222, 6/-222, 6//-222, 6//222, -7//2)
    print(-7%2)
    print(6%-132)
    print(6%-2)


if __name__ == '__main__':
    main()
